package com.bing.autoconfig;

import org.springframework.beans.factory.FactoryBean;

public class AnimalFactoryBean<T>  implements FactoryBean<T> {
    private Class<T> animalClass;

    public AnimalFactoryBean(Class<T> animalClass) {
        this.animalClass = animalClass;
    }
    public AnimalFactoryBean() {

    }

    @Override
    public T getObject() throws Exception {
        T t = this.animalClass.getDeclaredConstructor().newInstance();
        return t;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Class<T> getObjectType() {
        return this.animalClass;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isSingleton() {
        return true;
    }

    public Class<T> getAnimalClass() {
        return animalClass;
    }

    public void setAnimalClass(Class<T> animalClass) {
        this.animalClass = animalClass;
    }
}
